import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:work/pages/cashout/cashout_tab.dart';
import 'package:work/pages/earn/earn_tab.dart';
import 'package:work/pages/game/game_controller.dart';
import 'package:work/pages/game/game_tab.dart';
import 'package:work/pages/main/app_bottom_bar.dart';

import 'main_controller.dart';

class MainPage extends GetView<MainController> {
  /// 主页tabBar
  const MainPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Get.put(MainController());
    Get.put(GameController());

    return ColoredBox(
      color: Colors.white,
      child: Obx(() {
        return Visibility(
          visible: controller.visible.value,
          child: _buildMain(),
        );
      }),
    );
  }

  Widget _buildMain() {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: PageView(
        controller: controller.pageController,
        physics: const NeverScrollableScrollPhysics(),
        onPageChanged: controller.onPageChanged,
        children: const [
          GameTab(),
          EarnTab(),
          CashoutTab(),
        ],
      ),
      bottomNavigationBar: Obx(() {
        return AppBottomNavigationBar(
          items: MainController.items,
          current: controller.current.value,
          onChange: controller.pageController.jumpToPage,
        );
      }),
    );
  }
}
